"""
应用配置模块
"""

import os
from typing import Dict, Any


class Settings:
    """应用设置类"""
    
    # 数据库配置
    DATABASE_PATH = os.path.join('data', 'tasks.db')
    
    # 任务配置
    DEFAULT_PRIORITY = 'medium'
    DEFAULT_STATUS = 'todo'
    MAX_TITLE_LENGTH = 200
    MAX_DESCRIPTION_LENGTH = 1000
    
    # 显示配置
    TASKS_PER_PAGE = 20
    DATE_FORMAT = '%Y-%m-%d'
    DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
    
    # 导出配置
    EXPORT_FORMATS = ['json', 'csv']
    
    # 颜色配置（用于命令行显示）
    COLORS = {
        'high': 'red',
        'medium': 'yellow',
        'low': 'green',
        'todo': 'cyan',
        'in_progress': 'blue',
        'completed': 'green',
        'overdue': 'red',
        'warning': 'yellow',
        'error': 'red',
        'success': 'green',
        'info': 'blue'
    }
    
    # 状态和优先级的中文映射
    STATUS_LABELS = {
        'todo': '待办',
        'in_progress': '进行中',
        'completed': '已完成'
    }
    
    PRIORITY_LABELS = {
        'high': '高',
        'medium': '中',
        'low': '低'
    }
    
    # 状态和优先级的图标
    STATUS_ICONS = {
        'todo': '⏳',
        'in_progress': '🔄',
        'completed': '✅'
    }
    
    PRIORITY_ICONS = {
        'high': '🔴',
        'medium': '🟡',
        'low': '🟢'
    }
    
    @classmethod
    def get_database_path(cls) -> str:
        """获取数据库路径"""
        return cls.DATABASE_PATH
    
    @classmethod
    def get_color(cls, key: str) -> str:
        """获取颜色配置"""
        return cls.COLORS.get(key, 'white')
    
    @classmethod
    def get_status_label(cls, status: str) -> str:
        """获取状态中文标签"""
        return cls.STATUS_LABELS.get(status, status)
    
    @classmethod
    def get_priority_label(cls, priority: str) -> str:
        """获取优先级中文标签"""
        return cls.PRIORITY_LABELS.get(priority, priority)
    
    @classmethod
    def get_status_icon(cls, status: str) -> str:
        """获取状态图标"""
        return cls.STATUS_ICONS.get(status, '❓')
    
    @classmethod
    def get_priority_icon(cls, priority: str) -> str:
        """获取优先级图标"""
        return cls.PRIORITY_ICONS.get(priority, '⚪')
    
    @classmethod
    def to_dict(cls) -> Dict[str, Any]:
        """将设置转换为字典"""
        return {
            'database_path': cls.DATABASE_PATH,
            'default_priority': cls.DEFAULT_PRIORITY,
            'default_status': cls.DEFAULT_STATUS,
            'max_title_length': cls.MAX_TITLE_LENGTH,
            'max_description_length': cls.MAX_DESCRIPTION_LENGTH,
            'tasks_per_page': cls.TASKS_PER_PAGE,
            'date_format': cls.DATE_FORMAT,
            'datetime_format': cls.DATETIME_FORMAT,
            'export_formats': cls.EXPORT_FORMATS
        }


# 创建全局设置实例
settings = Settings()